package com.cn.hnust.controller;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cn.hnust.pojo.Film;
import com.cn.hnust.service.IFilmService;
import com.google.gson.Gson;

@Controller
@RequestMapping("/Film")
public class FilmController {

	@Resource
	private IFilmService filmService;

	@RequestMapping("/selectAllFilm")
	public void selectAllFilm(HttpServletResponse response,Film Film) throws IOException {
		List<Film> list = filmService.selectAllFilm();
		Gson gson = new Gson();
		String json = gson.toJson(list);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		response.setContentType("text/json,charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();
		out.write(json);
		out.flush();
	}
	
	@RequestMapping("/selectFilmByMifcArea")
	public void selectFilmByMifcArea(HttpServletResponse response,Film Film,String mifc,String area) throws IOException {

		List<Film> list = filmService.selectFilmByMifcArea(mifc, area);
	
		Gson gson = new Gson();
		String json = gson.toJson(list);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		response.setContentType("text/json,charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();
		out.write(json);
		out.flush();
	}
	
	@RequestMapping("/selectFilmByMnameActorTaici")
	public void selectFilmByMnameActorTaici(HttpServletResponse response,Film Film,String mname,String mactor,String taici) throws IOException {
			System.out.println("mname:"+mname+" mactor:"+mactor+" taci:"+taici);
		List<Film> list = filmService.selectFilmByMnameActorTaici(mname, mactor, taici);
		Gson gson = new Gson();
		String json = gson.toJson(list);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		response.setContentType("text/json,charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();
		out.write(json);
		out.flush();
	}
	
	@RequestMapping("/selectFilmById")
	public void selectFilmById(HttpServletResponse response,Film film,Integer id) throws IOException {
		
		film= filmService.selectFilmById(id);
		
		Gson gson = new Gson();
		String json = gson.toJson(film);
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		response.setContentType("text/json,charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();
		out.write(json);
		out.flush();
	}

}
